#include<bits/stdc++.h>
using namespace std;
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    int n,m,l,v,s[t]={0},kai[t]={0};
    for(int i=0;i<=t-1;i++)
    {
        cin>>n>>m>>l>>v;
        int di[n],vi[n],ai[n],mi[m],kk[m]={0};
        for(int j=0;j<=n-1;j++)
        {
            cin>>di[j]>>vi[j]>>ai[j];
        }
        for(int j=0;j<=m-1;j++)
            cin>>mi[j];
        for(int j=0;j<=n-1;j++)
        {
            if(ai[j]==0&&vi[j]>v)
            {
                for(int k=0;k<=m-1;k++)
                {
                    if(mi[k]>=di[j])
                    {
                        s[i]++;
                        kk[k]=1;
                        break;
                    }
                }
            }
            else if(vi[j]>v&&ai[j]<0)
            {
                int timee=0,vv=vi[j];
                do
                {
                    timee=timee+1;
                    vi[j]=vi[j]+ai[j];
                }while(vi[j]>=v);//
                int ss=di[j]+(vv*timee)+((ai[j]*timee*timee)/2);
                for(int k=0;k<=m-1;k++)
                {
                    if(mi[k]>=di[j]&&mi[k]<=ss)
                    {
                        s[i]++;
                        kk[k]=1;
                        break;
                    }
                }
            }
            else if(vi[j]<=v&&ai[j]>0)
            {
                int timee=0,vv=vi[j];
                do
                {
                    timee=timee+1;
                    vi[j]=vi[j]+ai[j];
                }while(vi[j]<=v);//
                int ss=di[j]+(vv*timee)+((ai[j]*timee*timee)/2);
                for(int k=0;k<=m-1;k++)
                {
                    if(mi[k]>=ss)
                    {
                        s[i]++;
                        kk[k]=1;
                        break;
                    }
                }
            }
            for(int j=0;j<=m-1;j++)
            {
                if(kk[j]==1) kai[i]++;
            }
        }
    }
    for(int i=0;i<=t-1;i++)
    {
        cout<<s[i]<<" "<<m-kai[i]<<endl;
    }

    fclose(stdin);
    fclose(stdout);
}
